<template>
    <div class="">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i> 企业认证列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
                        <!-- tabs -->
            <div class="handle-tab">
                <el-tabs v-model="activeTab" @tab-click="changState">
                    <el-tab-pane label="待审核" name=0></el-tab-pane>
                    <el-tab-pane label="审核通过" name=1></el-tab-pane>
                    <!-- <el-tab-pane label="审核不通过" name=2></el-tab-pane> -->
                </el-tabs>
            </div>
            <!-- <el-button type="primary" round @click="urlAdd"><i class="el-icon-plus"> </i>&nbsp;&nbsp;新增分站</el-button> -->
            <div style="height:40px"></div>
                <el-form :inline="true"  class="demo-form-inline">
                    <el-form-item label="公司名称:">
                        <el-input v-model="name" placeholder="请输入公司名称" clearable style="width:300px;"></el-input>
                    </el-form-item>
                    <el-form-item label="联系电话:">
                        <el-input v-model="mobile" placeholder="请输入联系电话" clearable style="width:300px;"></el-input>
                    </el-form-item>
    
                    <el-form-item>
                        <el-button type="primary" @click="onSelect"> &nbsp;&nbsp;查询&nbsp;&nbsp;  </el-button>
                        <el-button type="primary" @click="onResetting"> &nbsp;&nbsp;重置&nbsp;&nbsp;  </el-button>
                    </el-form-item>
                </el-form>
                <el-table :data="tableData"  style="width: 100%"   ref="multipleTable">
                    <el-table-column prop="id" label="ID" width="80" align="center">
                    </el-table-column>
                    <el-table-column label="企业营业执照" width="120" align="center">
                        <template slot-scope="scope" >
                            <div><img :src="scope.row.enterprise_license" style="width:80px;height:80px"></div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="enterprise_name" label="企业名称"  align="center">
                    </el-table-column>
                    <el-table-column prop="enterprise_type" label="企业性质" width="200" align="center">
                    </el-table-column>
                    <!-- <el-table-column prop="subStationCity" label="所属分站" width="100" align="center">
                    </el-table-column> -->
                    <el-table-column prop="contact" label="联系人" width="120" align="center">
                    </el-table-column>
                     <el-table-column prop="mobile" label="联系电话" width="150" align="center">
                    </el-table-column>
                    <!-- <el-table-column prop="address" label="联系地址" width="300" align="center">
                    </el-table-column> -->
                     <el-table-column prop="trans_is_checked" label="审核状态" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="操作" align="center" >
                        <template slot-scope="scope" >
                            <el-button class="edit" size="small" type="text" @click="handleLook(scope.$index, scope.row)">查看</el-button>
                            <el-button class="del" size="small" type="text"  @click="handleCheck(scope.$index, scope.row)" v-show="scope.row.is_checked==0">审核</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pagination" v-show="totalPages>1">
                    <el-pagination v-if="paginationShow" @current-change="handleCurrentChange" :current-page.sync="pageIndex" layout="prev, pager, next" :page-size="pageSize" :total="totalElements" background>
                    </el-pagination>
                </div>
        </div>
        <!-- 审核操作弹出界面 -->
        <el-dialog title="审核" :visible.sync="isChecked"  center width="450px">
            <el-form style="width:400px; margin:0 auto">
                <el-form-item label="企业名称">
                       {{eName}}
                </el-form-item>
                <el-form-item label="企业ID">
                        {{id}}
                </el-form-item>
                 <el-form-item label="审核状态">
                    <div>
                          <el-radio v-model="state" label="1" border>审核通过</el-radio>
                          <el-radio v-model="state" label="2" border>审核不通过</el-radio>
                    </div>
                </el-form-item> 
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="isChecked = false">取 消</el-button>
                <el-button type="primary" @click="confirmCheck">确 定</el-button>
            </div>
        </el-dialog>
        <!-- 删除提示框 -->
        <!-- <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow">确 定</el-button>
            </span>
        </el-dialog> -->
        <!-- / 删除提示框 -->
    </div>
</template>
<script>
import {getEnterpriseList,postChangeEnterprise,getEnterpriseDetaile} from '@/api/enterprise'
export default {
    name:"substationList",
    data() {
        return {
            pageIndex:1,//当前页码
            pageSize:10,//每页10条
            paginationShow:true,//重新显示分页
            totalElements:1,//默认的总条数
            totalPages:1,//默认的总页数
            tableData:[],//表格数据
            delVisible:false, //默认dialog 不弹出
            activeTab:"0",//tabs默认选中  发布分类：0待处理 1已处理     
            title:'', //商品标题
            name:'',//公司名称
            mobile:'',//联系电话
            options:[{value:0,label:'待处理'},{value:1,label:'审核通过'},{value:2,label:'审核不通过'}],//审核状态option选项
            value:0,//下来选中
            isChecked:false,//审核界面默认隐藏 true显示
            data:'',//获取到详情的数据
            state:"1",//审核状态  1审核通过，2审核不通过
            id:'',//当前用户di
            eName:'',//审核对象名称
        }
    },
    //实例创建
    created(){
        //
        this.getDate();
    },
    //计算属性
    computed:{

    },
    //方法
    methods: {
        //获取数据
        getDate(){
            getEnterpriseList(this.name,this.mobile,this.value,this.pageIndex,this.pageSize).then((response)=> {
                if(response.code==200){
                    var data = response.data;//当前返回的数据
                    this.tableData = data.list;//列表数据
                    this.totalElements = data.total; //总条数
                    this.totalPages = Math.ceil(data.total/this.pageSize);//总页数
                }else{
                    this.$notify.error({
                        title: '异常',
                        offset: 100,
                        message: response.msg
                    });
                }
            })
        },
        //发布
        urlAdd(){
            this.$router.push({ path:'/substation/add'})
        },
        //查询
        onSelect(){
            this.pageIndex =1;
            this.getDate();
        },
        //重置筛选条件
        onResetting(){
            this.name = '';
            this.mobile = '';
            this.getDate();
        },
         //tabs切换触发
        changState(tab) {
            this.activeTab = tab.name;//改变tab激活项
            this.value=tab.name;
            this.pageIndex=1;

                   this.paginationShow = false   //分页器消失
            this.$nextTick(function () {
                //分页器重新加载 解决element 分页器的无法触发current-change事件 只限在tabs页 
                this.paginationShow = true  
            })

            this.getDate();
        },
        //分页
        handleCurrentChange(val){
            this.pageIndex =val;
            this.getDate();
        },
        //查看详情
        handleLook(index,row){
            if(row.id && row.id>0){
                //跳转到详情页
                this.$router.push({ path: '/check/enterprise/details',query:{id:row.id}});
            }
        },
        //去审核（显示审核界面）
        handleCheck(index,row){
            console.log(index,row);
            if(row.id && row.id>0){
                this.id = row.id; //当前对象id
                this.eName = row.enterprise_name;//企业名称
                this.isChecked = true; //显示兑换弹出框
            }
        },
        // 确定提交审核
        confirmCheck(){
            let _this = this;
            if(this.id>0){
                // console.log(_this.id)
                postChangeEnterprise(_this.id,_this.state).then(response=>{
                    // console.log(response);
                    if(response.code==200){
                        _this.$message.success('操作成功');
                        _this.isChecked = false;
                        setTimeout(function(){
                            _this.getDate();
                        },1500)
                        
                    }else{
                        _this.$notify.error({
                            title: '操作失败',
                            duration:2000,
                            message: '失败原因：'+response.data.msg
                        });
                    }
                    
                })
            }
            
        }
        
    }
}
</script>
<style lang="stylus" scoped>
    .edit{
        color #ff9800;
    }
    .del{
        color #e51c23;
    }
    .download{
        color #67C23A;
    }
</style>


